#include "histomiddle.h"
#include "qpainter.h"
#include "colorname.h"

HistoMiddle::HistoMiddle(QWidget* parent):
    QWidget(parent)
{
    backColor = DpGray;
    mainColor = DpPepple;
    value = 40;
}

void HistoMiddle::paintEvent(QPaintEvent *)
{
    int width = this->width();
    int height = this->height();
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    painter.translate(width/2, height/2);
    int side = qMin(width, height);
    painter.scale(width / 20.0, height / 200.0);

    drawRange(&painter);
    drawValue(&painter);
}

void HistoMiddle::drawRange(QPainter *painter)
{
    painter->save();
    painter->setPen(Qt::NoPen);
    painter->setBrush(this->backColor);
    painter->drawRect(-10,-100,20,200);
    painter->restore();
}

void HistoMiddle::drawValue(QPainter *painter)
{
    painter->save();
    painter->setPen(Qt::NoPen);
    painter->setBrush(this->mainColor);
    if(this->value>0)
    {
        painter->drawRect(-10,0,20,this->value);
    }
    else
        painter->drawRect(-10,this->value,20,-1*this->value);
    painter->restore();
}

void HistoMiddle::setValue(float value)
{
    this->value = value;
}

void HistoMiddle::setBackColor(QColor color)
{
    this->backColor = color;
}

void HistoMiddle::setMainColor(QColor color)
{
    this->mainColor = color;
}
